home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 1.5 KB | 52 lines | [TEXT/GEOL] |
- Item forwarded by A33 to A34
-
- Item 5649548 18-Feb-90 14:54PST
-
- From: AUST0334 AUDev - CRIA, Canberra, ACT,IDV
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Nested Each with deletions
-
- I am using MacApp to develop a Paper Form generation package, and recently had
- cause to delete an element from a TList while in a method called under
- TList.Each, and then enter another Each loop.
-
- Now, I admit that this may seem quite strange, but is valid and sensible in the
- context I was using it.
- ( the first loop was processing DeSelection, and the second invoked a resulting
- update of screen layout.)
-
-
- Apparently the MacApp programmers consider this sensible also, as they seem to
- have mechanisms in place to cope with it. (i.e the fEachLevel counter and
- associated mechanisms).
-
- Unfortunately it failed, and the second invocation of Each did not process the
- last element in the list.
-
- The fix is, however, quite simple and safe.
- The loop which does the work in TList.Each normally looks like this:-
-
- for index := 1 to fSize do
- begin
- LONGINT(item) := PLongInt(Ord(Handle(SELF)^) + offset)^;
- if Ord(item) <> kDeletedElement then
- DoToItem(item);
- offset := offset + kElemSize;
- end;
-
- The fix is to modify the loop line to look like this :-
- for index := 1 to (fSize + fDeletions) do
-
- This ensures that the index traverses all the valid items and the deleted ones
- which have not yet been compacted out.
-
- Towards more unbreakable code,
-
- Don Lawn
-
-
-
-
-